package com.briup.pts.web.controller;

import com.briup.pts.config.response.Result;
import com.briup.pts.domain.bean.IndexRecord;
import com.briup.pts.service.IndexRecordService;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 25095
 * @description
 * @data 2024/11/27-20:16
 */
@Slf4j
@Tag(name="指标记录")
@RestController
@Validated
@RequiredArgsConstructor
@RequestMapping("/indexRecord")
public class IndexRecordController {
    private final IndexRecordService service;
     @Operation(summary = "分页多条件查询指标记录信息")
     @GetMapping("/query")
    public Result<?> query(@NotNull(message = "分页参数不能为空")
                           @Min(value = 1L, message = "当前页面不能小于1")
                           Integer pageNum,
                           @NotNull(message = "分页参数不能为空")
                           @Min(value = 1L, message = "当前页面不能小于1")
                           Integer pageSize,
                           Integer startWeight,Integer endWeight){
         log.info("当前页码:{},页面大小:{}", pageNum, pageSize);
         PageInfo<IndexRecord> pageInfo = service
                 .pageQueryByCondition(pageNum, pageSize,startWeight,endWeight);
         return Result.success(pageInfo)
                 .apply("获取成功");
     }

    @Operation(summary = "新增或修改动物指标记录数据")
    @PostMapping("/saveOrUpdate")
    public Result<?> saveOrUpdate(@Valid @RequestBody IndexRecord indexRecord) {
        service.saveIndexRecord(indexRecord);
        return Result.success(null).apply("新增成功");
    }

    @Operation(summary = "根据id删除指标记录")
    @DeleteMapping("/deleteById/{ird_id}")
    public Result<?> deleteById(@PathVariable Integer ird_id){
        service.deleteById(ird_id);
        return Result.success(null).apply("删除成功");
    }

    @Operation(summary = "批量删除指标记录")
    @DeleteMapping("/deleteByIdAll")
    public Result<?> deleteByIdAll(@RequestBody List<Integer> ids){
         service.deleteByIdAll(ids);
         return Result.success(null).apply("批量删除成功");
    }


}
